//
//  ContractScanViewController.swift
//  Hunter
//
//  Created by oher on 15/7/6.
//  Copyright © 2015年 刘🐑. All rights reserved.
//

import UIKit


//主控制器实现跳转
protocol ContractScanViewControllerDelegate : NSObjectProtocol{
    func forwardToAnoherController(CSController: ContractScanViewController, index: Int)
}



let CellReuseIdentifier = "CellReuseIdentifier"

class ContractScanViewController: UIViewController , UITableViewDelegate, UITableViewDataSource{

    weak var delegate : ContractScanViewControllerDelegate?
    
    @IBOutlet weak var dropdown: UIImageView!
    
    @IBOutlet weak var TableView: UITableView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        setTableView()
    }
    
    func setTableView(){
        TableView.delegate = self
        TableView.dataSource = self
        TableView.scrollEnabled = false
        TableView.backgroundColor = UIColor.clearColor()
        
        TableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: CellReuseIdentifier)
        TableView.separatorInset = UIEdgeInsets(top: 0, left: 15, bottom: 0, right: 15)
        TableView.rowHeight = 35
        TableView.separatorStyle = UITableViewCellSeparatorStyle.None
        
    }
    
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
        return 2
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{

        let cell = tableView.dequeueReusableCellWithIdentifier(CellReuseIdentifier, forIndexPath: indexPath)
        cell.backgroundColor = UIColor.clearColor()
        if indexPath.row == 0 {
            cell.textLabel?.text = "添加手机联系人"
        }else{
            cell.textLabel?.text = "扫一扫"
        }
        
        cell.selectionStyle = UITableViewCellSelectionStyle.None
        cell.textLabel?.textColor = UIColor.whiteColor()
        cell.textLabel?.font = UIFont.systemFontOfSize(14)
        return cell
    }
    
//    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
//        let cell = tableView.cellForRowAtIndexPath(indexPath)
//        cell?.backgroundColor = UIColor.clearColor()
//        cell?.contentView.backgroundColor = UIColor.clearColor()
//        cell?.backgroundView?.backgroundColor = UIColor.clearColor()
//        cell?.selectedBackgroundView?.backgroundColor = UIColor.orangeColor()
//        cell?.selectedBackgroundView?.layer.cornerRadius = 3
//        cell?.selectedBackgroundView?.layer.masksToBounds = true
//        tableView.deselectRowAtIndexPath(indexPath, animated: true)
//        cell?.selectionStyle = UITableViewCellSelectionStyle.None
//    }、
    
    func dismiss(){
        dismissViewControllerAnimated(true, completion: nil)
    }
    
    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

        dismiss()
        
        let viewController = UIViewController()
        viewController.view.backgroundColor = UIColor.greenColor()
        if indexPath.row == 0 {
            //可能跳转的工作不应该由弹出来的控制器来做
            delegate?.forwardToAnoherController(self, index: indexPath.row)
        } else{
            delegate?.forwardToAnoherController(self, index: indexPath.row)
        }

    }
    
}
